<?php
namespace Admin\Controller;

/*
 * 广告管理控制器
 */
class AdversController extends CommController {


    //Banner图片管理
    public function index(){
        $model = D('Banner');
        $condition =  array();

		//广告名称
		$search['adname'] 		= (string)I( 'post.adname' );
		if ( $search['adname'] ) 
    		$condition['name'] = array('like', '%'.$search['adname'].'%');
		
		//位置
		$search['type'] 		= (int)I( 'post.type', 0);
		if ( $search['type'] ) 
    		$condition['type'] = $search['type'];
		
		//是否前台显示
		$search['is_show'] 		= (int)I( 'post.is_show', 0);
		if ( $search['is_show'] ) 
    		$condition['is_show'] = $search['is_show']-1;

        $dataList = $this->getPageList( $model, $condition, 20, "addtime desc" );
		
		// 页面显示参数赋值
        $this->assign( "dataList", $dataList );
        $this->assign( 'search', $search );

        $this->display();
    }

	/**
	 * 插件一条数据
	 */
	public function create() {
		if($_POST['discount_start']){
			$_POST['discount_start'] = strtotime($_POST['discount_start']);
		}
		if($_POST['discount_end']){
			$_POST['discount_end'] = strtotime($_POST['discount_end']);
		}
		//判断  当时商铺管理员修改商品的时候   存入商铺下品牌id、

		$model = D ( 'Banner' );
		$refresh = $_POST ['refresh'] ? $_POST ['refresh'] : 'refreshClose';
		$return = $model->commInsert ( $_POST );
		$this->dwzSuccess ( $return ['info'], $return ['status'], $modelName, $refresh );
	}
	
	//审核
    public function check(){
    	$idList = I( 'post.id' );
		$status = I('get.status') == 'no' ? 1 : 0;
    	if ( D( 'Banner' )->where( array( 'id' => array( 'in', $idList ) ) )->save( array( 'is_show' => $status ) ) ) {
    		$this->dwzSuccess( '审核成功', 1, 'advers', 'refreshThis' );
    	} else {
    		$this->dwzSuccess( '审核失败，请重新操作', 0, 'advers', 'refreshThis' );
    	}
    }
	
	//网点地址列表
    public function networdAddr(){
        //获取广告分类
        $model = D('NetworkPoint');
        $condition =  array();

        $dataList = $this->getPageList( $model, $condition, 20, "time desc" );
		
		// 页面显示参数赋值
        $this->assign( "dataList", $dataList );
        $this->assign( 'search', $search );

        $this->display();
    }
	
	/**
	 * 删除一条或一组数据
	 * 
	 * @param $idList id列表
	 */
	public function remove() {
		$return = returnArray ();
		$idList = I ( 'post.id' );
		$condition ['id'] = array ( 'in', $idList  );
		$result = D('Banner')->where($condition)->delete ();
		if ($result !== false) {
			$return ['status'] = 1;
			$return ['info'] = '操作成功!';
		} else {
			$return ['status'] = '0';
			$return ['info'] = '操作失败!';
		}
		$this->dwzSuccess ( $return ['info'], $return ['status'], 'advers', "refreshThis" );
	}

	/**
	 * 显示编辑页面
	 */
	public function edit() {
		$id = I ( 'get.id' );
		$modelName = CONTROLLER_NAME;
		$model = D ( 'Banner' );
		$return = $model->getCommOne ( $id );
		if ($return ['status']) {
			$this->assign ( 'dataInfo', $return ['info'] );
		} else {
			die ( $return ['info'] );
		}
		
		$this->display ();
	}

	/**
	 * 修改一条数据
	 */
	public function update() {
		$modelName = CONTROLLER_NAME;
		$model = D ( 'Banner' );

		//判断  是刷新当前还是指定页面
		$refresh = $_POST ['refresh'] ? $_POST ['refresh'] : 'refreshClose';
		$return = $model->commUpdate ( $_POST );
		$this->dwzSuccess ( $return ['info'], $return ['status'], $modelName, $refresh );
	}
	
}

